////////////////////////////////////////////////////////////////////////////////
// Filename: d3dclass.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _D3DCLASS_H_
#define _D3DCLASS_H_

/////////////
// LINKING //
/////////////
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")

//////////////
// INCLUDES //
//////////////
#include <dxgi.h>
#include <d3dcommon.h>
#include <d3d11.h>
#include <xnamath.h>

////////////////////////////////////////////////////////////////////////////////
// Class name: D3DClass
////////////////////////////////////////////////////////////////////////////////
class CDirect3D
{
public:
	CDirect3D();
	CDirect3D(const CDirect3D&);
	~CDirect3D();

	static CDirect3D* Instance();

	bool Initialize(int screenWidth, int screenHeight, 
				    bool vsync, HWND hwnd, bool fullscreen, 
					float screenDepth, float screenNear);
	void Shutdown();
	
	void BeginScene(float red, float green, float blue, float alpha);
	void EndScene();

	ID3D11Device* GetDevice();
	ID3D11DeviceContext* GetDeviceContext();

	XMFLOAT4X4* GetProjectionMatrix();
	XMFLOAT4X4* GetWorldMatrix();
	XMFLOAT4X4* GetOrthoMatrix();

	void GetVideoCardInfo(char*, int&);

	void EnableDepthStencil();
	void DisableDepthStencil();
	void DisableWriteDepthStencil();

	void EnableRasterStateForDecal();
	void DisableRasterStateForDecal();

	void CreateTexture(int pWidth, int pHeight, ID3D11Texture2D** pTexture);
	void CreateDepthBuffer(int screenWidth, int screenHeight, ID3D11Texture2D** pTexture, ID3D11DepthStencilView** pStencilView);
private:

	void InitializeDepthStencilStates();

	static CDirect3D* mInstance;

	bool m_vsync_enabled;
	int m_videoCardMemory;
	char m_videoCardDescription[128];
	IDXGISwapChain* m_swapChain;
	ID3D11Device* m_device;
	ID3D11DeviceContext* m_deviceContext;
	ID3D11RenderTargetView* mRenderTargetView;
	D3D11_VIEWPORT mViewport;
	ID3D11Texture2D* mDepthStencilBuffer;
	ID3D11DepthStencilState* mDepthStencilState;
	ID3D11DepthStencilState* mDepthStencilDisableState;
	ID3D11DepthStencilState* mDepthStencilDisableWriteState;
	ID3D11DepthStencilView* m_depthStencilView;
	ID3D11RasterizerState* m_rasterState;
	ID3D11RasterizerState* m_rasterStateForDecal;
	XMFLOAT4X4 mProjectionMatrix;
	XMFLOAT4X4 mWorldMatrix;
	XMFLOAT4X4 mOrthoMatrix;
};

#endif